package com.xunyji.demo02weixinauthorization.web;

import com.alibaba.fastjson.JSONObject;
import com.xunyji.demo02weixinauthorization.comm.util.TransformUtils;
import com.xunyji.demo02weixinauthorization.model.weixin.UserBindDO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author AltEnter
 * @create 2019-01-13 14:29
 * @desc 测试控制层
 **/
@RestController
@Slf4j
@RequestMapping(value = "/test")
public class TestController {

    @GetMapping(value = "/connect")
    public String connect () {
        String msg = "前后端连接测试";
        log.info(msg);
        return msg;
    }

    public static void main(String[] args) {
        TransformUtils transformUtils = new TransformUtils();
        UserBindDO userBindDO = UserBindDO.builder()
                .account("王杨帅")
                .nickname("AltEnter")
                .build();
        log.info("原始值为：" + userBindDO);

        JSONObject jsonObject = transformUtils.object2JSONObject(userBindDO);
        log.info("转化成的JSON对象为：" + jsonObject);
        log.info("获取到的昵称值为：" + (String) jsonObject.get("nickname"));

        String jsonString = transformUtils.object2JSONString(userBindDO);
        log.info("转化成的JSON字符串为：" + jsonString);

        UserBindDO userBindDO1 = transformUtils.String2Object(jsonString, UserBindDO.class);
        log.info("字符串转化成UserBindDO对象为：" + userBindDO1);
    }

}

